package com.example.oj.service;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.oj.entity.JudgerStatus;
import com.example.oj.mapper.JudgerStatusMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class JudgerStatusService extends ServiceImpl<JudgerStatusMapper, JudgerStatus> {
    @Resource
    JudgerStatusMapper judgerStatusMapper;

    public Page<JudgerStatus> SelectPage(Integer pageNum, Integer pageSize, String select_pid, String select_username,
                                         String select_language,  String select_status) {
        LambdaQueryWrapper<JudgerStatus> wrapper = Wrappers.lambdaQuery();
        wrapper.like(JudgerStatus::getPid, select_pid).and
                (q1->{q1.like(JudgerStatus::getUsername, select_username);})
                        .and(q2->{q2.like(JudgerStatus::getLanguage, select_language)
                                .and(q3->{q3.like(JudgerStatus::getResult, select_status);});});

        Page<JudgerStatus> Page = new Page<>(pageNum, pageSize);
   //     Page.addOrder(OrderItem.asc("submittime")); // 按照 id 排序
        return judgerStatusMapper.selectPage(Page, wrapper);
    }
}
